﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MovingRobot
{
    public class Robot
    {
        Location _currentLocation;
        //Location PreviousLocation;
        Field _playground;
        
        public Robot(Field field)
        {
            if (field == null)
                throw new ArgumentNullException("field is null");
            _playground = field;
            _currentLocation = new Location(1,1);
            //PreviousLocation = CurrentLocation;
            
            

        }

        public Robot(int x, int y, Field field)
        {
            if (field == null)
                throw new ArgumentNullException("field is null");
            _playground = field;
            _currentLocation = new Location(x, y);
            //PreviousLocation = CurrentLocation;
            


        }
        private void MoveUp()
        {
            
            if (_currentLocation.Y > 1)
            {
                //PreviousLocation.Y = CurrentLocation.Y;
                _currentLocation.Y--;
            }
               
        }
        private void MoveDown()
        {
            if (_currentLocation.Y < (_playground.Height-1))
            {
                //PreviousLocation.Y = CurrentLocation.Y;
                _currentLocation.Y++;
            }
        }
        private void MoveLeft()
        {
            if (_currentLocation.X > 1)
            {
                //PreviousLocation.X = CurrentLocation.X;
                _currentLocation.X--;
            }
        }
        private void MoveRight()
        {
            if (_currentLocation.X < (_playground.Wight-1))
            {
                //PreviousLocation.X = CurrentLocation.X;
                _currentLocation.X++;
            }
        }
        public void Move(ConsoleKeyInfo keypress)
        {
             
            if (keypress.Key == ConsoleKey.UpArrow)
            {
                this.MoveUp();
            }
            if (keypress.Key == ConsoleKey.DownArrow)
            {
                this.MoveDown();
            }
            if (keypress.Key == ConsoleKey.LeftArrow)
            {
                this.MoveLeft();
            }
            if (keypress.Key == ConsoleKey.RightArrow)
            {
                this.MoveRight();
            }
         }

        public void Rend()
        {
            
            Console.SetCursorPosition(_currentLocation.X, _currentLocation.Y);
            Console.Write("#");
            Console.SetCursorPosition(_currentLocation.X, _currentLocation.Y);


        }
    }
}
